﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Model;

namespace Hazop
{
    public partial class hazardForm : Form{
        private List<TreeNode> _allKeys = new List<TreeNode>();
        public hazardForm()
        {
            InitializeComponent();
            _bindAskList.DataSource = null;
            dataGridView1.DataSource = _bindAskList;
            LoadData();
        }

        private void LoadData()
        {
            foreach (string key in Program.Workspace.HazardList.Keys){
                TreeNode node = new TreeNode(key);
                _allKeys.Add(node);
                tvChemical.Nodes.Add(node);
            }
        }

        private void tbxKeyWord_TextChanged(object sender, EventArgs e){
            string key = tbxKeyWord.Text;
            tvChemical.Nodes.Clear();
            foreach (TreeNode node in _allKeys) {
                if (node.Text.Contains(key)){
                    tvChemical.Nodes.Add(node);
                }
            }
        }

        private void tvChemical_AfterSelect(object sender, TreeViewEventArgs e){
            TreeNode node = tvChemical.SelectedNode;
            foreach (string key in Program.Workspace.HazardList.Keys)
            {
                if(node.Text.Equals(key)){
                    _bindAskList.DataSource = Program.Workspace.HazardList[key];
                }
            }
        }
    }
}
